package recharge_management

import (
	"context"

	"gitee.com/liuxuezhan/ar-platform/rpc-client/assetsClient/rpc"

	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type QrBankListLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// qr_bank--列表
func NewQrBankListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *QrBankListLogic {
	return &QrBankListLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *QrBankListLogic) QrBankList(req *types.QrBankListRequest) (resp *types.QrBankListResponse, err error) {
	rpcReq := rpc.QrBankListRequest{
		BankName: req.BankName,
	}

	rpcResp, err := l.svcCtx.AssetsRpc.TenantChannel.QrBankList(l.ctx, &rpcReq)
	if err != nil {
		return nil, err
	}
	var records []types.QrBank
	for _, record := range rpcResp.Records {
		records = append(records, types.QrBank{
			Id:           record.Id,
			CreatedAt:    record.CreatedAt,
			UpdatedAt:    record.UpdatedAt,
			MinAmount:    record.MinAmount,
			MaxAmount:    record.MaxAmount,
			DailyTimes:   record.DailyTimes,
			DailyAmount:  record.DailyAmount,
			RemainTimes:  record.RemainTimes,
			RemainAmount: record.RemainAmount,
			VisionLevel:  record.VisionLevel,
			IsDisplay:    record.IsDisplay,
			QrCode:       record.QrCode,
			BankNickname: record.BankNickname,
			BankName:     record.BankName,
			Sort:         record.Sort,
			Remark:       record.Remark,
		})
	}

	return &types.QrBankListResponse{
		Records: records,
		Pagination: types.Pagination{
			Page: 1,
		},
		CommonResp: types.CommonResp{
			Code:    rpcResp.CommonResp.Code,
			Message: rpcResp.CommonResp.Message,
		},
	}, nil
}
